#include<iostream>
using namespace std;
#include<queue>
#include<string>
typedef struct node{
	int data;
	struct node * lchild;
	struct node * rchild;
}BTNode,*BTree;
int count=0;
BTree CreateBtree(string str,int i)
{
	if(i>str.size()-1) return NULL;
	if(str[i]=='#') return NULL;
	BTree b;
	b=new BTNode;
	b->data=str[i]-'0';
	b->lchild=CreateBtree(str,2*i);
	b->rchild=CreateBtree(str,2*i+1);
	return b;
}
void WPL(BTree b,int n)
{
	if(b!=NULL)
	{
		if(b->lchild==NULL&&b->rchild==NULL)
		    count=count+b->data*n;
		WPL(b->lchild,n+1);
		WPL(b->rchild,n+1);
	}
}
int main()
{
	string str;
	cin>>str;
	BTree BT;
	BT=CreateBtree(str,0);
	WPL(BT,0);
	cout<<count;
	return 0;
}
